home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / ae.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  8.0 KB  |  377 lines

  1. #include "bbs.h"
  2. #include <dos.h>
  3. /*
  4. struct AEInfo {
  5.             struct MsgPort *WriteSerPort;
  6.             struct MsgPort *ReadSerPort;
  7.             struct MsgPort *WriteConPort;
  8.             struct MsgPort *ReadConPort;
  9.             struct MsgPort *TimerPort;
  10.             struct MsgPort *MyRexxPort;
  11.             struct MsgPort *StatWritePort;
  12.             struct MsgPort *ZmodemWritePort;
  13.             struct IOStdReq *StatWriteReq;
  14.             struct IOStdReq *ZmodemWriteReq;
  15.             struct IOExtSer *WriteSerReq,*ReadSerReq;
  16.             struct IOStdReq *WriteConReq,*ReadConReq;
  17.             struct Commands *Cmds;
  18.             UBYTE SOUT;
  19.             UBYTE COUT;
  20. };*/
  21. void getsystime(long number,char *d,char *t);
  22. int strwild(char *str,char *str1,char wild,int len)
  23. {
  24.     int i=0;
  25.    if(*(str+i)=='\0' || len==0) return(1);
  26.    while(*(str+i) && i<len)
  27.    {
  28.      if(*(str1+i)=='\0') return(1);
  29.      if(*(str1+i)==wild ) { i++; continue; }
  30.      if(*(str+i)!=*(str1+i)) return(1);
  31.      i++;
  32.    }
  33.    return(0);
  34. }
  35.  
  36. void strlim(char *str1,char *str2,int limit)
  37. {
  38.   int i=0;
  39.   int tlimit=0;
  40.   while(*(str2+tlimit)!='\0') tlimit++;
  41.   if(limit==-1) limit=tlimit;
  42.   while(i<limit)
  43.   {
  44.     if(i<tlimit) 
  45.     *(str1+i)=*(str2+i);
  46.     else *(str1+i)=' '; 
  47.     i++;
  48.   }
  49.   *(str1+i)='\0';
  50. }
  51.  
  52. #define addansi p=0; ansi->buf[ansi->ansicode]='\0'; while(ansi->buf[p]!='\0') \
  53.        { *(d+k)=ansi->buf[p]; k++; p++; }
  54.  
  55. void stripansi(char *s,char *d,struct ansi *ansi,int resetit,int strip)
  56. {
  57. // static int ansicode=0;
  58. // static char anrbuf[20];
  59.  register int i,j,k,p;
  60.  if(resetit) { ansi->ansicode=0; return; }
  61.  i=strlen(s);j=k=0;
  62.  while(j<i)
  63.  {
  64.    if(*(s+j)=='\r' && strip) { j++; ansi->ansicode=0; continue;}
  65.    if(!ansi->ansicode && *(s+j)!='') { *(d+k)=*(s+j); j++; k++; continue; }
  66.    else
  67.    {
  68.      if(ansi->ansicode)
  69.      {
  70.         ansi->buf[ansi->ansicode]=*(s+j);
  71.         if(ansi->ansicode==1 && *(s+j)!='[')
  72.         {
  73.            ansi->ansicode++; addansi ansi->ansicode=0; 
  74.         }
  75.         else
  76.         {
  77.            switch(*(s+j))
  78.            {
  79.             case 'm': ansi->ansicode=0; break;
  80.  default: ansi->ansicode++; if((*(s+j)>='A' && *(s+j)<='Z') ||
  81.                      (*(s+j)>='a' && *(s+j)<='z'))
  82.                      {
  83.                         addansi ansi->ansicode=0;
  84.                      } break;
  85.                  }
  86.        }
  87.      }
  88.      else if(*(s+j)=='') { ansi->buf[0]=''; ansi->ansicode=1; } 
  89.     }
  90.     j++;
  91.   }
  92.   *(d+k)='\0';
  93. }
  94. STRPTR GetTheDate(long number)
  95. {
  96.   char Date[22];
  97.   getsystime(number,Date,NULL);
  98.   return(Date);
  99. }
  100. STRPTR GetTheTime(long number)
  101. {
  102.   char temp[30];
  103.   getsystime(number,NULL,temp);
  104.  return(temp);
  105. }
  106.  
  107. void ConPutStr(char *s)
  108. {
  109.    if(KEYIN)
  110.    {
  111.          WriteConReq->io_Data   = (APTR)s;
  112.         WriteConReq->io_Length = strlen(s);
  113.      DoIO(WriteConReq);
  114.    }
  115. }
  116. void SerPutStr(unsigned char *string)
  117. {
  118.    if(SEROUT)
  119.    {
  120.          WriteSerReq->IOSer.io_Data   = (APTR)string;
  121.         WriteSerReq->IOSer.io_Length = strlen(string);
  122.      DoIO((struct IORequest *)WriteSerReq);
  123.    }
  124. }
  125. void ConPutChar(char *ch)
  126. {
  127.    if(KEYIN)
  128.    {
  129.          WriteConReq->io_Data   = (APTR)ch;
  130.         WriteConReq->io_Length = 1;
  131.      DoIO(WriteConReq);
  132.    }
  133. }
  134. void SerPutChar(char *ch)
  135. {
  136.    if(SEROUT)
  137.    {
  138.          WriteSerReq->IOSer.io_Data   = (APTR)ch;
  139.         WriteSerReq->IOSer.io_Length = 1;
  140.      DoIO((struct IORequest *)WriteSerReq);
  141.    }
  142. }
  143.  
  144. int CheckCon(void)
  145. {
  146.   if(KEYIN) return((int)CheckIO(ReadConReq));
  147.   return(0);
  148. }
  149. int CheckSer(void)
  150. {
  151.   if(SEROUT) return((int)CheckIO((struct IORequest *)ReadSerReq));
  152.   return(0);
  153. }
  154.  
  155. int SCheckInput(void)
  156. {
  157.   int result1=0,result2=0;
  158.   if(KEYIN) result1=CheckIO(ReadConReq);
  159.   if(SEROUT) result2=CheckIO((struct IORequest *)ReadSerReq);
  160.   return(result1||result2);
  161. }
  162.  
  163. void ConPutBlk(char *s,int length)
  164. {
  165.  if(KEYIN){
  166.      WriteConReq->io_Data   = (APTR)s;
  167.     WriteConReq->io_Length = length;
  168.      DoIO(WriteConReq);
  169.     }
  170. }
  171. void SerPutBlk(char *s,int length)
  172. {
  173.  if(SEROUT){
  174.      WriteSerReq->IOSer.io_Data   = (APTR)s;
  175.     WriteSerReq->IOSer.io_Length = length;
  176.      DoIO((struct IORequest *)WriteSerReq);
  177.     }
  178. }
  179.  
  180. BYTE CheckForNS(char *s)
  181. {
  182. char chr;
  183.  
  184. if(strlen(s)>1) {
  185.         chr=s[strlen(s)-2];
  186.         if(chr=='N'||chr=='n') {
  187.             chr=s[strlen(s)-1];
  188.             if(chr=='S'||chr=='s') {
  189.              return(1);
  190.             }
  191.         }
  192.     }
  193. return(0);
  194. }
  195. int CheckForAst(char *s)
  196. {
  197.   int i;
  198.    for(i=0; i<strlen(s); i++)  {
  199.      if(s[i]=='*' && GET_BIT(ACS_WILDCARDS))   return(i+1);
  200.  }
  201.  return(FALSE);
  202. }
  203. int GetUN(char *SA)
  204. {
  205. int x,N=0;
  206.  
  207. x=0;
  208.  while(*(SA+x)!='\0')
  209.  {
  210.    if(*(SA+x)=='@')
  211.    {
  212.      N=1; *(SA+x)='\0';x++;
  213.      break;
  214.    }
  215.    x++;
  216.  }
  217.  if(N) return(atoi((APTR)(SA+x)));
  218.  return(0);
  219. }
  220. int CompareTheseTwo(char *str,char *str2)
  221. {
  222. if(str[0]==str2[0])
  223.     {
  224.     if(str[1]==str2[1])
  225.         {
  226.         if(str[2]==str2[2])
  227.             {
  228.             return(SUCCESS);
  229.             }
  230.         }
  231.     }
  232. return(FAILURE);
  233. }
  234. void StripReturn(char *str)
  235. {
  236.   register i;
  237.   i=strlen(str)-1;
  238.   while(i>0)
  239.   {
  240.     if(*(str+i)<=32) *(str+i)='\0'; else return; 
  241.     i -=1;
  242.   }
  243. }
  244. int ProcessLine(char *pat,char *vorig,char *dest)
  245. {
  246.  int i,i2,nff;
  247.  char rep[80],orig[100];
  248.  
  249.  strcpy(orig,vorig);
  250.  for(i=0; i<=strlen(pat); i++) {
  251.      if(pat[i]==';') break;
  252.  }
  253.  
  254.  if(i>=strlen(pat)) return(0);
  255.  
  256.  pat[i]='\0';
  257.  strcpy(rep,(char *)&pat[i+1]);
  258.  
  259.  dest[0]='\0';
  260.  
  261.  for(i=0; i<=(strlen(orig)-strlen(pat)); i++) {
  262.      nff=1;
  263.      if(pat[0]==orig[i]) {
  264.          nff=0;
  265.          for(i2=i+1; (i2-i)<strlen(pat); i2++) {
  266.              if(pat[i2-i]!=orig[i2]) {
  267.                  nff=1;
  268.                  break;
  269.              }
  270.          }
  271.      }
  272.      if(nff!=1) {
  273.          orig[i]='\0';
  274.          strcpy(dest,orig);
  275.          strcat(dest,rep);
  276.          if(i2<strlen(vorig))    strcat(dest,(char *)&orig[i2]);
  277.          dest[75]='\0';
  278.          return(1);
  279.      }
  280.  }
  281.  return(0);
  282. }
  283. int jive(char *nam, char *pat)
  284. {
  285.  register char *p;              /* Thu Jan 16 14:50:30 1992 */
  286.  
  287.  for (;;)    {
  288.      if (tolower(*nam) == tolower(*pat))    {
  289.             if(*nam++ == '\0')  return(SUCCESS);
  290.             pat++;
  291.         }  else if (*pat == '?' && *nam != 0) {
  292.             nam++;
  293.             pat++;
  294.         } else    break;
  295.     }
  296.  
  297.  if (*pat != '*')    return(FAILURE);
  298.  while (*pat == '*') {
  299.         if (*++pat == '\0')  return(SUCCESS);
  300.     }
  301.  
  302.  for (p=nam+strlen(nam)-1;p>=nam;p--)    {
  303.         if (tolower(*p) == tolower(*pat))
  304.             if (jive(p,pat) == SUCCESS)   return(SUCCESS);
  305.     }
  306.  return(FAILURE);
  307. }
  308.  
  309. /*
  310.  * # seconds between 1-1-70 (Unix time base) and 1-1-78 (Amiga time base).
  311.  * Add this value to the returned seconds count to convert Amiga system time
  312.  * to normal Unix system time.
  313.  */
  314.  
  315. ULONG UnixTimeOffset = 252482400;
  316.  
  317. /**********************************************************
  318.  *    ULONG getsystime(struct timeval *tv)
  319.  *
  320.  *      This function was rewritten using DateStamp() to
  321.  * eliminate the opening and closing of the timer.device
  322.  * that was occurring everytime this function was called.
  323.  * An attempt to save some processing time.   -WMP-
  324.  **********************************************************/
  325. void getsystime(long number,char *d,char *t)
  326. {
  327.   struct DateStamp ds;
  328.    struct DateTime dt;
  329.    if(number==0L)
  330.    {
  331.      DateStamp(&ds);
  332.      dt.dat_Stamp=ds;
  333.    }
  334.    else
  335.    {
  336.       number -= UnixTimeOffset;
  337.       dt.dat_Stamp.ds_Days=number/(60L*60L*24L);
  338.                            number -= dt.dat_Stamp.ds_Days*(60L*60L*24L);
  339.       dt.dat_Stamp.ds_Minute=number/60L; 
  340.       dt.dat_Stamp.ds_Tick=0L;
  341.    }
  342.      dt.dat_Format=FORMAT_USA;
  343.    dt.dat_StrDay=NULL;
  344.    dt.dat_StrDate=d;
  345.    dt.dat_StrTime=t;
  346.    dt.dat_Flags=DTB_SUBST;
  347.    DateToStr(&dt);
  348. }
  349. void prbuf(char c);
  350.  
  351. int mysprintf(char *buffer, char *ctl, ...)
  352. {
  353.    long *arg1;
  354.  
  355.    arg1 = (long *) (&ctl + 1);
  356.    RawDoFmt(ctl, (APTR)arg1, prbuf, (APTR)buffer);
  357.    return((int)strlen (buffer));
  358.    }    /* End of int mysprintf() */
  359.  
  360. /**********************************************************
  361.  *    void prbuf(char c)
  362.  *
  363.  * This stub routine is called from the RawDoFmt routine for
  364.  * each character in the string.  At invocation, we have:
  365.  *   D0 - next character to be formatted
  366.  *   A3 - pointer to data buffer
  367.  **********************************************************/
  368. #define R_A3 (8 + 3)
  369.  
  370. void prbuf(char c)
  371. {
  372.    char *p = (char *) __builtin_getreg(R_A3);
  373.    *p++ = c;
  374.    __builtin_putreg(R_A3, (long) p);
  375.    }    /* End of void prbuf() */
  376.  
  377.